<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/8
 * Time: 16:25
 */
//post获取
$username = $_POST['username'];
$password = $_POST['password'];
$userkey = md5($username.$password);
$newurl = '';
$pstate = '';

//开启session
session_start();

//判断用户名
SqlUtils::$conn=new mysqli("127.0.0.1","root","123456","newbank");
$sql="select * from bankcard WHERE CardNo='".$username."' and CardPwd='".$password."'";
$result=count(SqlUtils::select($sql));
if($result>0){
    //设置cookie
    setcookie('userkey','userkey',time()+24*3600,'/');

    $pstate = '登录成功！';
    $newurl = 'p_userinfo.php';

    //设置session
    $_SESSION[userkey]=[
        'username'=>$username,
        'password'=>$password
    ];
}else{
    $pstate = '用户名密码错误！';
    $newurl = '/pp_login.php';
}
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
	<input type="hidden" name="newurl" id="newurl" value="<?php echo $newurl?>" />
	<input type="hidden" name="pstate" id="pstate" value="<?php echo $pstate?>" />
</body>
<script type="text/javascript">
onload = function(){
    var newurl = document.getElementById('newurl').value;
    var pstate = document.getElementById('pstate').value;
    alert(pstate);
    location.href=newurl;
}
</script>
</html>